<template>
  <div>
    <el-form label-position="top">
      <el-form-item label="创建路由（你可以假设上面是接口数据）">
        <el-button
          @click="onClick">
          添加页面
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import {cloneDeep} from 'lodash'
  import {mapState, mapMutations} from 'vuex'
  import {frameInRoutes} from '@/router/routes'
  import layoutHeaderAside from '@/views/layout/header-aside'

  export default {
    data() {
      return {}
    },
    computed: {
      ...mapState('d2admin/menu', [
        'header'
      ])
    },
    methods: {
      ...mapMutations({
        pageInit: 'd2admin/page/init',
        headerSet: 'd2admin/menu/headerSet'
      }),
      onClick() {
        let pageTitle = '工作流模板设计';
        let rpath = 'workflow/design';
        let rname = 'workflowDesign';
        const route = [
          {
            path: '/', component: layoutHeaderAside, children: [
              {path: rpath, name: rname, component: () => import('@/views/system/workflow/design'), meta: {title: pageTitle}}
            ]
          }
        ];
        this.$router.addRoutes(route);
        // 更新标签页池
        this.pageInit([...frameInRoutes, ...route]);

        // 跳转
        this.$router.push({name: rname, params: {modelId: '1'}})
      }
    }
  }
</script>
